<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>生成器类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.stdclass.html">« stdClass</a></li>
      <li style="float: right;"><a href="generator.current.html">Generator::current »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reserved.interfaces.html">预定义接口和类</a></li>
    <li>生成器类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.generator" class="reference">
 
 <h1 class="title">生成器类</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p>


  <div class="section" id="generator.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    <span class="classname"><strong class="classname">Generator</strong></span> 对象是从 <a href="language.generators.html" class="link">generators</a>返回的.
   </p>
   
   <div class="caution"><strong class="caution">警告</strong>
    <p class="para">
     <span class="classname"><strong class="classname">Generator</strong></span> 对象不能通过
     <a href="language.oop5.basic.html#language.oop5.basic.new" class="link">new</a> 实例化.
    </p>
   </div>

  </div>


  <div class="section" id="generator.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <span class="modifier">class</span> <strong class="classname">Generator</strong>
     </span>
     
     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.iterator.html" class="interfacename">Iterator</a></span> {</div>
    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="generator.current.html" class="methodname">current</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.getreturn.html" class="methodname">getReturn</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.key.html" class="methodname">key</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.next.html" class="methodname">next</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.rewind.html" class="methodname">rewind</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.send.html" class="methodname">send</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.throw.html" class="methodname">throw</a></span>(<span class="methodparam"><span class="type"><a href="class.throwable.html" class="type Throwable">Throwable</a></span> <code class="parameter">$exception</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.valid.html" class="methodname">valid</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="generator.wakeup.html" class="methodname">__wakeup</a></span>(): <span class="type"><span class="type void">void</span></span></div>

   }</div>


  </div>

  <div class="section" id="generator.seealso">
   <h2 class="title">参见</h2>
   <p class="para">也可以参考 <a href="language.oop5.iterations.html" class="link">遍历对象</a>。</p>
  </div>

 </div>

 








 








 








 








 








 








 








 








 









<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="generator.current.html">Generator::current</a> — 返回当前产生的值</li><li><a href="generator.getreturn.html">Generator::getReturn</a> — 获取生成器的返回值</li><li><a href="generator.key.html">Generator::key</a> — 返回当前产生的键</li><li><a href="generator.next.html">Generator::next</a> — 生成器继续执行</li><li><a href="generator.rewind.html">Generator::rewind</a> — 重置迭代器</li><li><a href="generator.send.html">Generator::send</a> — 向生成器中传入一个值</li><li><a href="generator.throw.html">Generator::throw</a> — 向生成器中抛入一个异常</li><li><a href="generator.valid.html">Generator::valid</a> — 检查迭代器是否被关闭</li><li><a href="generator.wakeup.html">Generator::__wakeup</a> — 序列化回调</li></ul>
</div>
</div></div></body></html>